{% extends 'master.html' %}
{% block publish_funcs %}{% load publish_funcs %}{% endblock %}
{% block All %}
		<div id="wrapper">
        <div id="page-wrapper">
            <div class="row">
                <div class="col-lg-12">
                    <h1 class="page-header">Redis信息查看</h1>
                </div>
                <!-- /.col-lg-12 -->
            </div>
            <!-- /.row -->
            <div class="row">
                <div class="col-lg-12">
                    <div class="panel panel-default">
                        <div class="panel-heading">
														<span style="font-size:16px;">Redis实时信息查看</span>
												</div>
                        <!-- /.panel-heading -->
                        <div class="panel-body">
                            <table width="100%" class="table table-striped table-bordered table-hover" id="dataTables-example">
															  <thead>
																		<tr>
																				<th>序号</th>
																				<th>归属项目</th>
																				<th>别名</th>
																				<th>主机名</th>
																				<th>主机IP</th>
																				<th>端口</th>
																				<th>运行环境</th>
																				<th>备注</th>
                                        <!--<th>选择查询库</th>-->
																				<th>操作</th>
																		</tr>
																</thead>
																<tbody id="dataTables-body">
																		{% for row in redisinfos %}
																				<tr>
																						<td>{{ forloop.counter }}</td>
                                            <td>{{ row.project__projectname }}</td>
                                            <td>{{ row.redisname }}</td>
                                            <td>{{ row.hostname }}</td>
                                            <td>{{ row.hostip }}</td>
                                            <td>{{ row.port }}</td>
                                            <td>{{ row.environment__pathname}}</td>
                                            <td>{{ row.remarks }}</td>
                                            <td>
                                              <button id="selectRedis" onclick="selectRedis('{{ row.id }}')" type="button" class="btn btn-primary">实时信息查看</button>
                                            </td>
																				</tr>
																		{% endfor %}
																</tbody>
                            </table>
                            <!-- /.table-responsive -->

                        </div>
                        <!-- /.panel-body -->
                    </div>
                    <!-- /.panel -->

                <div class="col-lg-6">
                    <div class="panel panel-default">
                        <div class="panel-heading">
                          <h5>{{ hardware.minion_id }} Redis INFO信息</h5>
                        </div>
                        <!-- /.panel-heading -->
                        <div class="panel-body">
                            <div id="info" class="alert alert-info">
                                <H3>请查询.....</H3>
                            </div>

                        </div>
                        <!-- .panel-body -->
                    </div>
                    <!-- /.panel -->
                </div>
								<div class="col-lg-6">
                    <div class="panel panel-default">
                        <div class="panel-heading">
                            Redis DB Keys总览
                        </div>
                        <!-- /.panel-heading -->
                        <div class="panel-body">
															<div id="keys" class="alert alert-success">
                                  <H3>请查询.....</H3>
                            	</div>

                        </div>





                        <!-- .panel-body -->
                    </div>
                    <!-- /.panel -->
                </div>

                </div>
                <!-- /.col-lg-12 -->
            </div>
        </div>
        <!-- /#page-wrapper -->
    </div>
    <!-- /#wrapper -->
{% endblock %}

{% block username %}{{ username }}{% endblock %}


{% block adminscript %}
<script>
//	表格相关的
		$(document).ready(function() {
				$('#dataTables-example').DataTable({
						responsive: true
				});
		});
</script>
<script>
  function selectRedis(redisId) {
    $('#selectRedis').val('查询中...')
    $.ajax({
			url:'/backend/redesinfo',
			type:'POST',
			data:{'redisId':redisId,csrfmiddlewaretoken: '{{ csrf_token }}' },
			success:function(result){
				var obj = JSON.parse(result);
				if(obj.isFalg){
					$('#info').text('');
					$('#keys').text('');
					$.each(obj.redisinfo,function (key,value) {
					  var s = key + ':' +value
					  $("#info").append("<p>"+ s + "</p>");
          });
					if(obj.rediskeys){
					  $.each(obj.rediskeys,function (key,value) {
					  $("#keys").append("<p>"+ '数据库：'+ key+ "</p>");
					  $("#keys").append("<p>"+ '对应的Keys：'+ value + "</p>");
					  $("#keys").append("<br/>");
          });
          }else{
					  alert(obj.rediskeys);
					  $('#keys').text('目前没有任何keys');
          }
				}else{
				  alert(obj.message);
					$('#info').text('请确认后查询');
					$('#keys').text('请确认后查询');
				}
			}
		})
    $('#selectRedis').val('实时信息查看')
  }
</script>
{% endblock %}